import static java.lang.Thread.sleep;

public class Demo12 {
    public static void main(String[] args) throws InterruptedException {
        Thread thread = new Thread(() -> {
            while (!Thread.currentThread().isInterrupted()) {
                System.out.println(Thread.currentThread().getName());
                try {
                    sleep(1000);
                } catch (InterruptedException e) {
//                    throw new RuntimeException(e);
//                    break;
                }
            }
        });
        thread.start();

        for (int i = 0; i < 3; i++) {
            System.out.println(Thread.currentThread().getName());
            sleep(1000);
        }
        thread.interrupt();
    }
}
